package com.wlyuan.open.scanner.utils.enums;


import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum YesOrNoEnum implements NamedValue<Integer> {
    NO(0, "否"),
    YES(1, "是"),
    ;

    private final Integer value;
    private final String name;

    private static final Map<Integer, YesOrNoEnum> MAP = new NamedValueMap<>(YesOrNoEnum.class);

    public static Integer fromValue(Integer value) {
        return Optional.ofNullable(value).map(a -> Optional.ofNullable(MAP.get(a).value).orElse(YesOrNoEnum.NO.value)).orElse(YesOrNoEnum.NO.value);
    }

    public static boolean isYes(Integer val) {
        return YES.value.equals(val);
    }

    public static boolean isNo(Integer val) {
        return NO.value.equals(val);
    }

}
